<?php

namespace app\model;

use app\utils\DateUtil;
use think\Model;

class CustomerCreditCard extends Model
{

    protected $table = 'customer_credit_card';

    public function creditCardList(int $customerId)
    {
        $fields = [
            'id as credit_card_id',
            '`organization_name`',
            '`open_time`',
            '`total_amount`',
            '`bill_day`',
            '`is_logout`',
        ];
        return $this
            ->where([['customer_id', '=', $customerId], ['status', '=', '1']])
            ->field($fields)
            ->select()
            ->toArray();
    }

    public function repaymentNoticeList()
    {
        $fields = [
            'id as credit_card_id',
            '`organization_name`',
            '`open_time`',
            '`total_amount`',
            '`bill_day`',
            '`customer_id`',
            '`is_logout`',
        ];
        return $this
            ->where([['bill_day', 'in', [DateUtil::oneDay(), DateUtil::twoDay()]], ['is_logout', '=', '0']])
            ->field($fields)
            ->select()
            ->toArray();
    }

    public function payNoticeList()
    {
        $fields = [
            'id as credit_card_id',
            '`organization_name`',
            '`open_time`',
            '`total_amount`',
            '`bill_day`',
            '`customer_id`',
            '`is_logout`',
        ];
        return $this
            ->where([['bill_day', 'in', [DateUtil::backOneDay(), DateUtil::backTwoDay()]], ['is_logout', '=', '0']])
            ->field($fields)
            ->select()
            ->toArray();
    }

    public function modifyDataById(int $creditCardId, array $data)
    {
        return $this->where(['id' => $creditCardId])->update($data);
    }
}